package com.zhanghao.sdk.util;

import com.zhanghao.sdk.callback.IRunCallback;
import com.zhanghao.sdk.model.TimeLong;


public class FunctionUtils {
    /**
     * 节流执行函数
     * @param functionTimeLong 缓冲区 存放旧的时间
     * @param callback 执行的函数
     */
    public static void throttleExecute(TimeLong functionTimeLong, IRunCallback callback) {
        long currentTime = TimeUtils.TimeMillis();
        long oldTime = functionTimeLong.getmLong();
        if (oldTime == 0) {
            functionTimeLong.setmLong(currentTime);
            callback.execute();
            return;
        }
        if (oldTime + 500 >= currentTime) {
            ZHLog.i("[频繁操作]");
            return;
        }
        callback.execute();
        functionTimeLong.setmLong(currentTime);
    }
}
